package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.AppUpdateLog;
import com.ruoyi.system.mapper.AppUpdateLogMapper;
import com.ruoyi.system.service.AppUpdateLogService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * app更新记录表(AppUpdateLog)表服务实现类
 *
 * @author makejava
 * @since 2023-02-15 09:46:02
 */
@Service("appUpdateLogService")
public class AppUpdateLogServiceImpl implements AppUpdateLogService {
    @Resource
    private AppUpdateLogMapper appUpdateLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AppUpdateLog queryById(Integer id) {
        return this.appUpdateLogDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param appUpdateLog 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AppUpdateLog> queryByPage(AppUpdateLog appUpdateLog, PageRequest pageRequest) {
        long total = this.appUpdateLogDao.count(appUpdateLog);
        return new PageImpl<>(this.appUpdateLogDao.queryAllByLimit(appUpdateLog, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param appUpdateLog 实例对象
     * @return 实例对象
     */
    @Override
    public AppUpdateLog insert(AppUpdateLog appUpdateLog) {
        appUpdateLog.setCreatedBy("sys");
        appUpdateLog.setCreatedDate(new Date());
        this.appUpdateLogDao.insert(appUpdateLog);
        return appUpdateLog;
    }

    /**
     * 修改数据
     *
     * @param appUpdateLog 实例对象
     * @return 实例对象
     */
    @Override
    public AppUpdateLog update(AppUpdateLog appUpdateLog) {
        this.appUpdateLogDao.update(appUpdateLog);
        return this.queryById(appUpdateLog.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.appUpdateLogDao.deleteById(id) > 0;
    }
}
